﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace List
{
    public class Node<T>
    {
        public Node<T> Next { get; set; }
        public T Data { get; set; }

        public Node(T t)
        {
            Next = null;
            Data = t;
        }
    }

    public class GenericList<T>
    {
        private Node<T> head;
        private Node<T> tail;

        public GenericList()
        {
            tail = head = null;
        }

        public Node<T> Head
        {
            get => head;
        }

        public void Add(T t)
        {
            Node<T> n = new Node<T>(t);
            if (tail == null)
            {
                head = tail = n;
            }
            else
            {
                tail.Next = n;
                tail = n;
            }
        }

        public void ForEach(Action<T> action)
        {
            for(Node<T> x = head; x != null; x = x.Next)
            {
                action(x.Data);
            }
        }
    }
    class Program
    {
        int GetSum(GenericList<int> genList)
        {
            int sum = 0;
            Action<int> action = x => sum += x;
            genList.ForEach(action);
            return sum;
        }
        static void Main(string[] args)
        {
            GenericList<int> genList = new GenericList<int>();
            Init();
            Print();
            Console.WriteLine(GetSum(genList));
            Console.WriteLine(GetMax(genList));
            Console.WriteLine(GetMin(genList))
        }
    }
}
